package com.kfh.ybracelet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kfh.ybracelet.R;
import com.kfh.ybracelet.bean.WhiteListResult;
import com.kfh.ybracelet.utils.CommonUtils;

import java.util.List;

/**
 * 手环白名单adapter
 * Created by Aaron on 15/8/7.
 */
public class WhiteListAdapter extends BaseAdapter {

    private Context context;
    public List<WhiteListResult.White> whiteList;

    public WhiteListAdapter(Context context, List<WhiteListResult.White> whiteList) {
        this.context = context;
        this.whiteList = whiteList;
    }

    public void setData(List<WhiteListResult.White> whiteList) {
        this.whiteList = whiteList;
    }

    @Override
    public int getCount() {
        return whiteList.size();
    }

    @Override
    public Object getItem(int position) {

        return whiteList.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_safe_area, null);
            viewHolder = new ViewHolder();

            viewHolder.tv_left_item = (TextView) convertView.findViewById(R.id.tv_left_item);
            viewHolder.tv_right_item = (TextView) convertView.findViewById(R.id.tv_right_item);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (whiteList == null)
            return convertView;

        viewHolder.tv_left_item.setText(CommonUtils.isNull(whiteList.get(position).name) ? "" : whiteList.get(position).name);
        viewHolder.tv_right_item.setText(CommonUtils.isNull(whiteList.get(position).phoneNum) ? "" : whiteList.get(position).phoneNum);

        return convertView;
    }

    private class ViewHolder {
        TextView tv_left_item;
        TextView tv_right_item;
    }

}
